<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="sn" prop="sn">
        <el-input
          v-model="queryParams.sn"
          placeholder="请输入Sn"
          clearable
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="mac" prop="mac" label-width="80px">
        <el-input
          v-model="queryParams.mac"
          placeholder="请输入mac"
          clearable
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleEmpty"
          v-hasPermi="['device:log:empty']"
        >清空</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="deviceLogList">
      <el-table-column label="sn号" align="center" prop="sn" width="170"/>
      <el-table-column label="设备Mac" align="center" prop="mac" width="170" />
      <el-table-column label="文件地址" align="center" prop="logUrl" />
      <el-table-column label="上报时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime)}}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listDeviceLog, emptyDeviceLog} from "@/api/platform/device/log/config";

export default {
  name: "DeviceLog",
  data() {
    return {
      operationType: true,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      deviceLogList: [],
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      detailOpen: false,
      // 是否显示添加修改弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询模板列表 */
    getList() {
      this.loading = true;
      listDeviceLog(this.queryParams).then(response => {
        this.deviceLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 清空按钮操作 */
    handleEmpty() {
      let data={}
      emptyDeviceLog(data).then(response =>{
        this.$modal.msgSuccess("清空成功");
        this.getList()
      })
    },
  }
};
</script>
